<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="js/bootstrap/css/bootstrap.css">
    <script src="js/jquery/jquery.min.js"></script>
    <script src="js/bootstrap/js/bootstrap.js"></script>
    <script>
        $(function (){
            $(".btn-info").click(function (){
                var form = $("#insertForm").serialize();
                $.ajax({
                    url:'/departments',
                    type:'POST',
                    data:form,
                    success:function (obj){
                        if (obj.success){
                            alert("操作成功");
                        }else {
                            alert("操作失败");
                        }
                    }

                });
            });

            $(".btn-danger").click(function (){
                var form = $("#deleteForm").serialize();
                $.ajax({
                    url:'/departments',
                    type:'DELETE',
                    data:form,
                    success:function (obj){
                        if (obj.success){
                            alert("操作成功");
                        }else {
                            alert("操作失败");
                        }
                    }

                });
            });

            $(".btn-link").click(function (){
                var id = $("#selectForm input").val();
                $.ajax({
                    url:'/departments/2',
                    type:'get',
                    success:function (obj){
                        if (obj.success){
                            alert(obj.list[0].name);
                        }else {
                            alert("操作失败");
                        }
                    }

                });
            });

        });


    </script>
</head>
<body>
    <form id="insertForm">
        名称：<input type="text" name="name"><br>
        简称：<input type="text" name="sn">
    </form>
    <button class="btn btn-info">验证Restful风格</button>
    <form id="deleteForm">
        <input type="text" name="id">
    </form>
    <button class="btn btn-danger">点击删除</button>

    <form id="selectForm">
        <input type="text" name="id">
    </form>
    <button class="btn btn-link">查询一个</button>
</body>
</html>